package com.hqq;

import com.hqq.dao.StudentDao;
import com.hqq.entity.Student;
import com.hqq.service.StudentService;
import com.hqq.service.impl.StudentServiceImpl;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class test {

    /**
     * 直接测试dao
     */
    @Test
    public void testInsert(){
        String config = "applicationContext.xml";
        ApplicationContext ac = new ClassPathXmlApplicationContext(config);
        //获取容器中的dao对象 对象名是接口首字母小写
        StudentDao da = (StudentDao)ac.getBean("studentDao");

        Student student = new Student(122,"qyh","qyh@qq",20);
        int num = da.insertStudent(student);
        System.out.println(num);

    }

    /**
     * 测试service
     */
    @Test
    public void testServiceInsert(){
        String config = "applicationContext.xml";
        ApplicationContext ac = new ClassPathXmlApplicationContext(config);
        //获取容器中的dao对象 对象名是接口首字母小写
        StudentService service = (StudentService)ac.getBean("studentService");

        Student student = new Student(123,"qyhhqq","qyh@hqq",5);
        int num = service.addStudent(student);
        System.out.println(num);
    }
}
